﻿using Assistant.Report.Method.Hr;
using Assistant.Report.Method.Sale;
using Newtonsoft.Json;
using OdooRpcClient.Model.Hr;
using PortaCapena.OdooJsonRpcClient.Result;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using WebAssistant.Common;
using static Assistant.Controllers.PrintController;
using static Assistant.Controllers.PrintModel;

namespace Assistant.Report
{
    public class ReportAction : Shared
    {
        public static PrintAction action;
        public static PrintContext context;
        public static Dictionary<string, object> data;

        /// <summary>
        /// 根据报表名称返回报表JSON格式的字符串数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="printAction"></param>
        /// <returns></returns>
        public static async Task <DataSet> GetReportDataTable<T>(PrintAction printAction)
        {
            action = printAction;
            context = printAction.Context;
            data = printAction.DataTables;

            DataSet ds = new DataSet();

            switch (printAction.ReportName)
            {
                #region HR

                case "hr.print_employee_badge":
                    DataTable dtBadgeEmployees = await PrintEmployeeBadge.GetReportContextDataTable();
                    DataTable dtBadgeParameters = PrintEmployeeBadge.GetReportParametersDataTable();
                    ds.Tables.Add(dtBadgeEmployees);
                    ds.Tables.Add(dtBadgeParameters);
                    return ds;
                case "hr_holidays.report_holidayssummary":
                    DataTable dtHolidaysEmployees = await ReportHolidaysSummary.GetHolidaysSummaryContextDataTable();
                    DataTable dtHolidaysParameters = ReportHolidaysSummary.GetHolidaysSummaryDataDataTable();
                    DataTable dtMonthsAndDays = ReportHolidaysSummary.GetMonthsAndDays();
                    ds.Tables.Add(dtHolidaysEmployees);
                    ds.Tables.Add(dtHolidaysParameters);
                    ds.Tables.Add(dtMonthsAndDays);
                    return ds;

                #endregion

                #region Sale
                case "sale.report_saleorder":
                    DataTable dtSaleOrder = await ReportSaleOrder.GetOrderDataTable();
                    DataTable dtSaleOrderLine = await ReportSaleOrder.GetOrderLineDataTable();
                    DataTable dtSaleOrderParameters = ReportSaleOrder.GetReportParametersDataTable();
                    ds.Tables.Add(dtSaleOrder);
                    ds.Tables.Add(dtSaleOrderLine);
                    ds.Tables.Add(dtSaleOrderParameters);
                    return ds;

                #endregion

                default:
                    return ds;

            }
        }


    }
}
